<template>
  <svg
    aria-hidden="true"
    :class="svgClass"
    :fill="props.color"
    :width="width"
    :height="height"
    v-bind="$attrs"
  >
    <use :xlink:href="iconName" />
  </svg>
</template>
<script setup lang="ts" name="svg-icon">
const props = defineProps({
  prefix: {
    type: String,
    default: "icon",
  },
  name: {
    type: String,
    required: true,
  },
  size: {
    type: String,
    default: "1em",
  },
  width: {
    type: String,
  },
  height: {
    type: String,
  },
  color: {
    type: String,
    default: "currentColor",
  },
  class: {
    type: String,
    default: "",
  },
});
const iconName = computed(() => `#${props.prefix}-${props.name}`);
const width = computed(() => (props.width ? props.width : props.size));
const height = computed(() => (props.height ? props.height : props.size));
const svgClass = computed(() => {
  if (props.class) {
    return `svg-icon ${props.class}`;
  }
  return "svg-icon";
});
</script>
<style scope lang="less">
.svg-icon {
  fill: currentColor;
  outline: none;
  vertical-align: middle;
}
</style>
